package com.holdtime.jtt809dataservice.client.process;

import com.holdtime.jtt809dataservice.client.config.BtjjXytParentPlatfromConfig;
import com.holdtime.jtt809dataservice.client.socket.TcpClient;
import com.holdtime.jtt809dataservice.common.domain.LinkStatusManager;
import com.holdtime.jtt809dataservice.common.event.MessageReceiveEvent;
import com.holdtime.jtt809dataservice.common.process.TransmitProtocolProcessor;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import protocol.jtt809.JTT809Packet;
import protocol.jtt809.body.RawBody;
import protocol.jtt809.body.UpExgMsg;

/**
 * author: sunwei
 * Date: 2025/3/23 08:46
 * Description:
 */
@Slf4j
@Component
public class ClientUpExgMsgProcessor implements TransmitProtocolProcessor {
    @Resource
    private TcpClient subordinatePlatformClient;
    @Resource
    private BtjjXytParentPlatfromConfig btjjXytParentPlatfromConfig;

    @Override
    public int getMsgID() {
        return UpExgMsg.MSG_ID;
    }

    @Override
    public void process(MessageReceiveEvent event) {
        JTT809Packet<RawBody> source = event.getSource();
        if (LinkStatusManager.getCurrent().getMainLinkStatus(source.getMsgGnsscenterid()) != null) {
            if (subordinatePlatformClient.isConnected()) {
                source.setMsgGnsscenterid(btjjXytParentPlatfromConfig.getJrm());
                subordinatePlatformClient.send(source);
            }
        }
    }
}
